﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for ProductCategory
/// </summary>
public class ProductCategory
{
    #region"Properties"
    public int MaLoai { get; set; }
    public String TenLoai { get; set; }
    #endregion"End Properties"

    #region"Methods"
    /// <summary>
    /// Thêm LoaiLapTop
    /// </summary>
    /// <param name="p"></param>
    public static void InsertLapTopCategory(ProductCategory p)
    {
        try
        {
            String StoredProcedureName = "sp_InsertLapTopCategory";
            IDictionary<String, String> d = new Dictionary<String, String>();
            d.Add("@MaLoai", p.MaLoai.ToString());
            d.Add("@TenLoai", p.TenLoai);
            DataAccess.ExecuteNonQuery(StoredProcedureName, d);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    /// <summary>
    /// Cập nhật LoaiLapTop
    /// </summary>
    /// <param name="p"></param>
    public static void UpdateLapTopCategory(ProductCategory p)
    {
        try
        {
            String StoredProcedureName = "sp_UpdateLapTopCategory";
            IDictionary<String, String> d = new Dictionary<String, String>();
            d.Add("@MaLoai", p.MaLoai.ToString());
            d.Add("@TenLoai", p.TenLoai);
            DataAccess.ExecuteNonQuery(StoredProcedureName, d);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    /// <summary>
    /// Xóa LoaiLapTop
    /// </summary>
    /// <param name="p"></param>
    public static void DeleteLapTopCategory(ProductCategory p)
    {
        try
        {
            String StoredProcedureName = "sp_DeleteLapTopCategory";
            IDictionary<String, String> d = new Dictionary<String, String>();
            d.Add("@MaLoai", p.MaLoai.ToString());
            DataAccess.ExecuteNonQuery(StoredProcedureName, d);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    /// <summary>
    /// Lấy danh sách tất cả các LoaiLapTop
    /// </summary>
    /// <returns></returns>
    public static List<ProductCategory> GetAllLapTopCategoryList()
    {
        try
        {
            List<ProductCategory> list = new List<ProductCategory>();
            String StoredProcedureName = "sp_GetAllLapTopCategoryList";
            String connectionString = DataAccess.ConnectionString;
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand comd = new SqlCommand(StoredProcedureName, con);
            con.Open();
            SqlDataReader datareader = comd.ExecuteReader(CommandBehavior.CloseConnection);
            if (datareader.HasRows)
            {
                while (datareader.Read())
                {
                    ProductCategory p = new ProductCategory()
                    {
                        MaLoai = int.Parse(datareader["MaLoai"].ToString()),
                        TenLoai = datareader.GetString(1)
                    };
                    list.Add(p);
                }
            }
            return list;
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    #endregion"End Methods"
}
